package com.fzebu.fastboot.db.builder;

import com.fzebu.fastboot.db.intl.AbstractSQLBuilder;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author Jack
 * @version 1.0.0
 * @create 2020/2/25 12:15
 */
public class SQLBuilderFactory {

    private static final Map<Class<?>, InsertBuilder> INS_BUILDER_MAP = new ConcurrentHashMap<>();

    public static AbstractSQLBuilder getSqlBuilder(Object object) {
        if (object == null || object.getClass().getClassLoader() == null) {
            throw new IllegalArgumentException("Object are not custom classes");
        }
        Class<?> clazz = object.getClass();
        InsertBuilder builder = INS_BUILDER_MAP.get(clazz);
        if (builder == null) {
            builder = new InsertBuilder(object);
            INS_BUILDER_MAP.put(clazz, builder);
        }
        builder.convert2Params(object);
        return builder;
    }
}
